package cn.whb.hrm.config;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class CourseNoticeListener {

    public static final String COURSE_ONLINE_NOTICE_QUEUE_SMS="course_online_notice_queue_sms";
    public static final String COURSE_ONLINE_NOTICE_QUEUE_EMALI="course_online_notice_queue_emali";
    public static final String COURSE_ONLINE_NOTICE_QUEUE_SYSTEM="course_online_notice_queue_system";


    //监听
    @RabbitListener(queues ={COURSE_ONLINE_NOTICE_QUEUE_SMS})
    public void sendSms(String msg, Message message, Channel channel) throws IOException {
        System.out.println("课程："+msg+"开课了");
        channel.basicAck(message.getMessageProperties()
                .getDeliveryTag(), false);
    }

    @RabbitListener(queues ={COURSE_ONLINE_NOTICE_QUEUE_EMALI})
    public void sendEmail(String msg, Message message, Channel channel) throws IOException {
        System.out.println("课程："+msg+"开课了");
        channel.basicAck(message.getMessageProperties()
                .getDeliveryTag(), false);
    }

    @RabbitListener(queues ={COURSE_ONLINE_NOTICE_QUEUE_SYSTEM})
    public void sendSystem(String msg, Message message, Channel channel) throws IOException {
        System.out.println("课程："+msg+"开课了");
        channel.basicAck(message.getMessageProperties()
                .getDeliveryTag(), false);
    }

}
